package com.tedu.ds.evaluationFeedback.service.impl;

import com.tedu.ds.evaluationFeedback.mapper.FeedbackMapper;
import com.tedu.ds.evaluationFeedback.pojo.dto.FeedbackQuery;
import com.tedu.ds.evaluationFeedback.pojo.dto.FeedbackSaveParam;
import com.tedu.ds.evaluationFeedback.pojo.entity.Feedback;
import com.tedu.ds.evaluationFeedback.pojo.vo.FeedbackPage;
import com.tedu.ds.evaluationFeedback.pojo.vo.FeedbackVO;
import com.tedu.ds.evaluationFeedback.service.FeedbackService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class FeedbackServiceImpl implements FeedbackService {
    @Autowired
    private FeedbackMapper feedbackMapper;

    @Override
    public void save(FeedbackSaveParam param) {
        Feedback feedback = new Feedback();
        BeanUtils.copyProperties(param,feedback);
        if(feedback.getId()==null) {
            feedback.setStatus("待反馈");
            feedbackMapper.save(feedback);
        }else{
            feedback.setStatus("已完成");
            feedbackMapper.update(feedback);
        }
    }

    @Override
    public void deleteById(Long id) {
        feedbackMapper.deleteById(id);
    }

    @Override
    public FeedbackPage select(FeedbackQuery query) {
        List<FeedbackVO> list = feedbackMapper.select(query);
        int total = feedbackMapper.count(query);
        FeedbackPage page = new FeedbackPage();
        page.setTotal(total);
        page.setList(list);
        return page;
    }
}
